package com.study.edoc.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 统一的全局异常类
 */
@RestControllerAdvice
public class GlobalExceptionHandler{


    /**
     * 处理系统自定义的业务异常
     * @param ex
     * @return
     */
    @ExceptionHandler(value = {BusinessException.class})
    public R exceptionHandler(BusinessException ex){
        return R.error(ex.getCode(),ex.getMsg());
    }



    /**
     * 处理系统默认未知异常
     * @param ex
     * @return
     */
    @ExceptionHandler(value = {Exception.class})
    public R defaultErrorHandler(Exception ex){
        return R.error(ResultCodeEnum.SERVER_ERROR.getCode(), ResultCodeEnum.SERVER_ERROR.getMsg());
    }
}
